#pragma once

#include "AddStructuralFeatureValueAction.h"

#include "InputPin.h"

namespace uml {

const bool AddStructuralFeatureValueAction::isReplaceAll_default_ = false;
AddStructuralFeatureValueAction::AddStructuralFeatureValueAction(const QString& umlType)
    : WriteStructuralFeatureAction(umlType) {}

void AddStructuralFeatureValueAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    WriteStructuralFeatureAction::fromJson(json, errorList);
    insertAt_ = JsonSerializable::create<InputPin>(json.value("insertAt"), errorList);

    isReplaceAll_ = json.value("isReplaceAll").toBool(isReplaceAll_default_);
}

void AddStructuralFeatureValueAction::toJson(QJsonObject& json) {
    WriteStructuralFeatureAction::toJson(json);
    if (insertAt_) {
        QJsonObject insertAt_json;
        insertAt_->toJson(insertAt_json);
        json.insert("insertAt", insertAt_json);
    }
    if (isReplaceAll_ != isReplaceAll_default_) {
        json.insert("isReplaceAll", isReplaceAll_);
    }
}

/// <summary>
/// insertAt getter
/// The InputPin that gives the position at which to insert the value in an ordered
/// StructuralFeature. The type of the insertAt InputPin is UnlimitedNatural, but
/// the value cannot be zero. It is omitted for unordered StructuralFeatures.
/// </summary>
shared_ptr<InputPin> AddStructuralFeatureValueAction::insertAt() const {
    return insertAt_;
}

/// <summary>
/// insertAt setter
/// The InputPin that gives the position at which to insert the value in an ordered
/// StructuralFeature. The type of the insertAt InputPin is UnlimitedNatural, but
/// the value cannot be zero. It is omitted for unordered StructuralFeatures.
/// </summary>
void AddStructuralFeatureValueAction::setInsertAt(shared_ptr<InputPin> value) {
    insertAt_ = value;
}

/// <summary>
/// isReplaceAll getter
/// Specifies whether existing values of the StructuralFeature should be removed
/// before adding the new value.
/// </summary>
bool AddStructuralFeatureValueAction::isReplaceAll() const {
    return isReplaceAll_;
}

/// <summary>
/// isReplaceAll setter
/// Specifies whether existing values of the StructuralFeature should be removed
/// before adding the new value.
/// </summary>
void AddStructuralFeatureValueAction::setIsReplaceAll(bool value) {
    isReplaceAll_ = value;
}

} // namespace uml
